package com.example.day1031_dataeven.slice;

import ohos.data.search.model.IndexData;
import ohos.data.search.schema.CommonItem;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.ArrayList;
import java.util.List;

public class Students {

    private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, "My_AG");
    /**
     * 女
     */
    public static final int GENDER_FEMALE = 0;
    /**
     * 男
     */
    public static final int GENDER_MALE = 1;

    /**
     * 姓名
     */
    private String name;

    /**
     * 学号
     */
    private int numbers;

    private int age;
    /**
     * 性别 0是女 1是男
     */
    private int gender;
    /**
     * 成绩(为了方便 就用整数表示)
     */
    private int grade;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumbers() {
        return numbers;
    }

    public void setNumbers(int numbers) {
        this.numbers = numbers;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }

    /**
     * 创建学生信息
     *
     * @return
     */
    public static List<Students> createStudentInfo() {

        List<Students> students = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            Students student = new Students();
            student.setName("熊猫" + i);
            student.setNumbers(i);
            student.setAge((i + 1) * 2);
            student.setGender(i % 2);
            student.setGrade(30 + i * 3);
            students.add(student);
        }
        return students;
    }

    /**
     * 融合搜索接口查询到的数据 转成Student结构，方便使用
     * (不转也可以，这不是本节重点)
     *
     * @param searchs 融合搜索接口查询到的数据
     * @return List<Student> Student信息列表
     */
    public static List<Students> buildStudentInfos(List<IndexData> searchs) {
        HiLog.info(LABEL_LOG, "buildStudentInfos"  + searchs.size());


        List<Students> students = new ArrayList<>();
        if (searchs != null && searchs.size() > 0) {
            for (int i = 0; i < searchs.size(); i++) {
                IndexData data = searchs.get(i);
                Students student = new Students();
                student.setName(data.getAsString(CommonItem.NAME));
                student.setNumbers(Integer.valueOf(data.getAsString(CommonItem.IDENTIFIER)));
                student.setAge((data.getAsInteger("age")));
                student.setGender(data.getAsInteger("gender"));
                student.setGrade(data.getAsInteger("grade"));

                students.add(student);
            }
        }
        return students;
    }

    @Override
    public String toString() {
        return "Students{" +
                "name='" + name + '\'' +
                ", numbers=" + numbers +
                ", age=" + age +
                ", gender=" + gender +
                ", grade=" + grade +
                '}';
    }
}
